<template>
	<view class="p-20">
		<view class="bg-white p-30 border-radius">
			<view class="form-item mb-40">
				<view class="font-bold font-28">类型</view>
				<view class="mt-20">
					<uni-data-checkbox v-model="form.type" :localdata="job_nature" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">标题</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.title" placeholder="请输入" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">联系方式</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.mobile" placeholder="请输入" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">信息</view>
				<view class="mt-20">
					<uni-easyinput auto-height type="textarea" v-model="form.info" placeholder="请输入" />
				</view>
			</view>
		</view>
		<view class="bottom-view flex flex-colum flex-center">
			<view class="bottom-btn font-white bg-g" @click="submit">发布职位</view>
			<view class="bottom-btn font-white bg-red mt-20" @click="del" v-if="showDel">删除</view>
		</view>
	</view>
</template>

<script>
	import {
		add,queryById,del,edit
	} from '../../api/obb.js'
	export default {
		data() {
			return {
				form: {
					info: '工作信息：\n工作城市：\n工作地点：\n薪资范围：\n工作时间：\n联系方式：\n'
				},
				job_nature: [{
					text: '零活',
					value: 0
				}, {
					text: '零工',
					value: 1
				}],
				showDel: false,
				id: ''
			};
		},
		onLoad(options) {
			if (options.id) {
				this.showDel = true
				this.id = options.id
				this.getDetail()
			}
		},
		methods: {
			del() {
				const _this = this
				this.$tips.showModal('是否删除该信息？', () => {
					del({
						id: this.form.id
					}).then(res => {
						if (res.code === 200) {
							_this.$tips.showConfirmModal('删除成功', () => {
								uni.navigateBack()
							})
						} else {
							_this.$tips.showConfirmModal('删除失败', () => {})
						}
					})
				}, () => {})
			},
			getDetail() {
				queryById({
					id: this.id
				}).then(res => {
					this.form = res.result
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			submit() {
				const _this = this
				this.$tips.showModal('是否提交保存？', () => {
					// _this.$tips.showConfirmModal('提交成功，请等待审核', () => {})
					if (!this.showDel) {
						add({...this.form}).then(res => {
							if (res.code === 200) {
								_this.$tips.showConfirmModal('提交成功，请等待审核', () => {
									uni.navigateBack()
								})
							} else {
								_this.$tips.showConfirmModal('提交失败，请重试', () => {
								})
							}
						})
					} else {
						edit({...this.form}).then(res => {
							if (res.code === 200) {
								_this.$tips.showConfirmModal('提交成功，请等待审核', () => {
									uni.navigateBack()
								})
							} else {
								_this.$tips.showConfirmModal('提交失败，请重试', () => {
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
		padding-bottom: 200rpx;
	}

	.bottom-view {
		width: 100vw;
		padding: 40rpx 0;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99999;
		border-top: 1px solid #efefef;

		.bottom-btn {
			width: 80vw;
			text-align: center;
			border-radius: 50rpx;
			padding: 20rpx 0;
		}
	}
</style>